import math
import numpy as np
def calculate_distance(p1, p2, scaled_x, scaled_y):
    """ 计算两个点之间的欧几里得距离 """
    return math.sqrt(((p1.x - p2.x)/scaled_x) ** 2 + ((p1.y - p2.y)/scaled_y) ** 2 + ((p1.z - p2.z) ** 2))
def cal_rectangle(hand_landmarks):
        # 计算边界框的最小和最大坐标
        min_x = min([landmark.x for landmark in hand_landmarks.landmark])
        min_y = min([landmark.y for landmark in hand_landmarks.landmark])
        max_x = max([landmark.x for landmark in hand_landmarks.landmark])
        max_y = max([landmark.y for landmark in hand_landmarks.landmark])
        return min_x, min_y, max_x, max_y
def get_all_distances(hand_landmarks):
    """计算边界"""
    min_x, min_y, max_x, max_y = cal_rectangle(hand_landmarks)
    scaled_x = abs(max_x - min_x)
    scaled_y = abs(max_y - min_y)
    """ 计算 hand_landmarks 中所有点两两之间的距离 """
    landmarks = hand_landmarks.landmark
    num_landmarks = len(landmarks)
    distances = []
    for i in range(num_landmarks):
        for j in range(i + 1, num_landmarks):
            distance = calculate_distance(landmarks[i], landmarks[j], scaled_x, scaled_y)
            distances.append(distance)

    return np.array(distances)